package cn.zwx.member.svc.fallback;

import cn.zwx.base.entity.ResponseEntity;
import cn.zwx.base.enums.ResponseCodeEnum;
import cn.zwx.member.svc.facade.CaptchaServiceApi;
import cn.zwx.member.svc.vo.GenCaptchaVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author zhangwenxue
 */
@Component
public class CaptchaApiFallback implements FallbackFactory<CaptchaServiceApi> {
    private static final Logger logger = LoggerFactory.getLogger(AddressApiFallback.class);

    @Override
    public CaptchaServiceApi create(Throwable cause) {
        logger.error("调用Member-Service fallback",cause);
        return new CaptchaServiceApi() {
            @Override
            public ResponseEntity<GenCaptchaVO> getCaptcha() {
                logger.error("getCaptcha fallback",cause);
                return ResponseEntity.fail(ResponseCodeEnum.RPC_ERROR.getCode(),cause.getMessage());
            }

            @Override
            public CaptchaApiFallback create(Throwable cause) {
                logger.error("调用Member-Service fallback",cause);
                return null;
            }
        };
    }
}
